package mn.slide.labmed.info;

import java.util.ArrayList;

import mn.slide.labmed.R;
import mn.slide.labmed.SearchListActivity;
import mn.slide.labmed.detail.MerkAndVerluafActivity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

public class InfoTabGroupActivity extends ActivityGroup
{

	public static InfoTabGroupActivity	group;
	private ArrayList<View>				history;
	Animation							animationSlideInLeft;

	Animation							outToLeft , inFromRight , inFromLeft ,
			outToRight;

	public InfoTabGroupActivity()
	{

	}

	@Override
	protected void onCreate( Bundle savedInstanceState )
	{
		super.onCreate(savedInstanceState);
		this.history = new ArrayList<View>();
		group = this;
		View view = getLocalActivityManager().startActivity("ListView", new Intent(this, InfoActivity.class)).getDecorView();
		replaceView(view);
		animationSlideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
		animationSlideInLeft.setDuration(500);
	}

	public void goNewsList( int i )

	{
		Intent intent;
		if (i == 1)
		{
			intent = new Intent(getApplicationContext(), BenutzActivity.class);
		}
		else if (i == 2)
		{
			intent = new Intent(getApplicationContext(), UberActivity.class);
		}
		else if (i == 3)
		{
			intent = new Intent(getApplicationContext(), KontaktActivity.class);
		}
		else
		{
			intent = new Intent(getApplicationContext(), ImpressumActivity.class);
		}

		View view = getLocalActivityManager().startActivity("ListView1", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		InfoTabGroupActivity.group.replaceView(view);
	}

	public void goSearchActivity( String value )
	{

		Intent intent = new Intent(getApplicationContext(), SearchListActivity.class);
		intent.putExtra("activity", "info");
		intent.putExtra("type", "search");
		intent.putExtra("key", value);
		View view = getLocalActivityManager().startActivity("ListView1", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		InfoTabGroupActivity.group.replaceView(view);
	}

	public void goSearchDetail( String value )
	{

		Intent intent = new Intent(getApplicationContext(), SearchListActivity.class);
		intent.putExtra("activity", "info");
		intent.putExtra("type", "main");
		intent.putExtra("modelid", value);
		View view = getLocalActivityManager().startActivity("ListView1", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		InfoTabGroupActivity.group.replaceView(view);

	}

	public void goSearchMerkAndVerluaf( String value )
	{

		Intent intent = new Intent(getApplicationContext(), MerkAndVerluafActivity.class);
		intent.putExtra("activity", "info");
		intent.putExtra("type", "main");
		intent.putExtra("modelid", value);
		View view = getLocalActivityManager().startActivity("ListView1", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		InfoTabGroupActivity.group.replaceView(view);

	}

	public void replaceView( View v )
	{
		if (history.size() != 0)
		{
			outToLeft = AnimationUtils.loadAnimation(this, R.anim.out_to_left);
			View v1 = history.get(history.size() - 1);
			v1.setAnimation(outToLeft);
			inFromRight = AnimationUtils.loadAnimation(this, R.anim.in_from_right);
			v.setAnimation(inFromRight);
		}
		history.add(v);
		setContentView(v);
	}

	public void back()
	{
		inFromLeft = AnimationUtils.loadAnimation(this, R.anim.in_from_left);
		outToRight = AnimationUtils.loadAnimation(this, R.anim.out_to_right);
		if (history.size() > 1)
		{
			View v = history.get(history.size() - 1);
			v.setAnimation(outToRight);
			history.remove(history.size() - 1);
			v = history.get(history.size() - 1);
			v.setAnimation(inFromLeft);
			setContentView(v);

		}
		else
		{
			finish();
		}
	}

	@Override
	public void onBackPressed()
	{
		if (history.size() != 1)
			InfoTabGroupActivity.group.back();
		else
			System.exit(0);
		return;
	}

}